Welcome to Ryan Lewe's Movie Query Page <p>  CS 143: Project 1B
<form action="query.php" method="post">
Type a MYSQL SELECT expression in the following box (e.g., SELECT * FROM Actor WHERE id < 20):<p>
<TEXTAREA input type="text" NAME="query" ROWS=10 COLS=50>
</TEXTAREA>

<input type="submit" value = "Query it up!"/>
<p>Database's RESULT: <p>
<?php
  $query= $_POST["query"];#get query from http
  $db_connection = mysql_connect("localhost", "cs143", "");#connect to MYSQL
  if(!$db_connection) {#Return error if unable to connect
    $errmsg = mysql_error($db_connection);
    print "Connection failed: $errmsg <br />";
    exit(1);
  }
  mysql_select_db("CS143", $db_connection);#select the CS143 database
  $sanitized_name = mysql_real_escape_string($name, $db_connection); #Remove special characters to avoid hacking
  $query_to_issue = sprintf($query, $sanitized_name);
  $rs = mysql_query($query_to_issue, $db_connection);#Evaluate MYSQL request

  for($ind = 0; $ind < mysql_num_fields($rs); $ind++){//Print Labels
    print mysql_field_name($rs, $ind);
    if($ind + 1 < mysql_num_fields($rs))
      print "  |  ";
  }
  print "</br>";
  while($row = mysql_fetch_row($rs)) {# output rest of mysql request data
    for($ind = 0; $row[$ind]; $ind++){ 
      print "$row[$ind]";
      if($row[$ind+1])
	print "  |  ";
    }
    print "</br>";
  }
  mysql_close($db_connection);
?>
